package org.erp.admins.controller;

import org.erp.admins.infrastructure.convert.PaymentChannelsConvert;
import org.erp.admins.domain.bo.PaymentChannelsBo;
import org.erp.admins.domain.dto.PaymentChannelsDto;
import org.erp.admins.domain.vo.PaymentChannelsVo;
import org.erp.admins.service.PaymentChannelsService;
import org.erp.common.page.DataPageResp;
import org.erp.common.page.PageQueryModel;
import org.erp.common.domain.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static org.erp.common.domain.Result.success;
/**
 * 支付渠道信息
 */
@RestController
@RequestMapping("/payment/channels")
public class PaymentChannelsController {
    @Resource
    private PaymentChannelsService paymentChannelsService;

    @Resource
    private PaymentChannelsConvert paymentChannelsConvert;
    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("/getListByPage")
    public Result<DataPageResp<PaymentChannelsVo>> getListByPage(PaymentChannelsBo bo) {
        PaymentChannelsDto dto = paymentChannelsConvert.boConvertDto(bo);
        PageQueryModel<PaymentChannelsVo> qm = paymentChannelsService.getListByPage(dto);
        return success(DataPageResp.of(qm.getTotal(), qm.getDataList()));
    }
    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("/getList")
    public Result<List<PaymentChannelsVo>> getList(PaymentChannelsBo bo) {
        PaymentChannelsDto dto = paymentChannelsConvert.boConvertDto(bo);
        return Result.success(paymentChannelsService.getPaymentChannelsVoList(dto));
    }
    /**
     * 通过id查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result<PaymentChannelsVo> selectOne(@PathVariable Long id) {
        return Result.success(paymentChannelsService.getPaymentChannelsVoById(id));
    }
    /**
     * 新增数据
     *
     * @param dto 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    public Result<Boolean> insert(@RequestBody PaymentChannelsDto dto) {
        boolean result = paymentChannelsService.addPaymentChannels(dto);
        return result ? Result.success("新增成功") : Result.error("新增失败");
    }
    /**
     * 修改数据
     *
     * @param dto 实体对象
     * @return 修改结果
     */
    @PostMapping("/upd")
    public Result<Boolean> update(@RequestBody PaymentChannelsDto dto) {
        boolean result = paymentChannelsService.updPaymentChannels(dto);
        return result ? Result.success("修改成功") : Result.error("修改失败");
    }
   /**
     * 删除数据
     *
     * @return 删除结果
     */
    @PostMapping("/del")
    public Result<Boolean> delete(@RequestBody PaymentChannelsBo bo) {
        boolean result = paymentChannelsService.removeById(bo.getId());
        return result ? Result.success("删除成功") : Result.error("删除失败");
    }
}

